6 #define D(x) cout << #x " = " << (x) << endl
13 int dist(point
&a
, point
&b
){
14 int dx
= abs(a
.x
- b
.x
);
15 int dy
= abs(a
.y
- b
.y
);
16 int dz
= abs(a
.z
- b
.z
);
17 return min(dx
, min(dy
, dz
));
20 const int MAXNODES
= 100000;
21 int p
[MAXNODES
], rank
[MAXNODES
];
22 void make_set(int x
){ p
[x
] = x
, rank
[x
] = 0; }
23 void link(int x
, int y
){
24 if (rank
[x
] > rank
[y
]) p
[y
] = x
;
25 else{ p
[x
] = y
; if (rank
[x
] == rank
[y
]) rank
[y
]++; }
28 return x
!= p
[x
] ? p
[x
] = find_set(p
[x
]) : p
[x
];
30 void merge(int x
, int y
){ link(find_set(x
), find_set(y
)); }
37 for (int i
= 0; i
< n
; ++i
){
38 cin
>> p
[i
].x
>> p
[i
].y
>> p
[i
].z
;
42 vector
< pair
<int, pair
<int, int> > > edges
;
43 for (int i
= 0; i
< n
; ++i
){
44 for (int j
= i
+ 1; j
< n
; ++j
){
45 edges
.push_back(make_pair( dist(p
[i
], p
[j
]), make_pair(i
, j
)));
48 sort(edges
.begin(), edges
.end());
50 for (int i
= 0; i
< edges
.size(); ++i
){
51 int u
= edges
[i
].second
.first
;
52 int v
= edges
[i
].second
.second
;
53 int w
= edges
[i
].first
;
54 if (find_set(u
) != find_set(v
)){